// import type { AxiosRequestConfig } from "axios";
// import requests from "@/utils/request/index";
// import type { ApiRequestOptions } from "@/api/client/core/ApiRequestOptions";
// import type { OpenAPIConfig } from "@/api/client/core/OpenAPI";
// import { CancelablePromise } from "@/api/client/core/CancelablePromise";

// const buildUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
//   const encoder = config.ENCODE_PATH || encodeURI;
//   const path = options.url.replace(/{(.*?)}/g, (substring: string, group: string) => {
//     if (options.path?.hasOwnProperty(group)) return encoder(String(options.path[group]));
//     return substring;
//   });
//   return path;
// };

// const getFormData = (options: ApiRequestOptions): FormData | undefined => {
//   if (!options.formData) return undefined;
//   const fd = new FormData();
//   Object.entries(options.formData)
//     .filter(([, v]) => v !== undefined && v !== null)
//     .forEach(([k, v]) => {
//       if (Array.isArray(v))
//         v.forEach((i) =>
//           fd.append(k, typeof i === "string" || i instanceof Blob ? i : JSON.stringify(i))
//         );
//       else fd.append(k, typeof v === "string" || v instanceof Blob ? v : JSON.stringify(v));
//     });
//   return fd;
// };

// export const request = <T>(
//   config: OpenAPIConfig,
//   options: ApiRequestOptions
// ): CancelablePromise<T> => {
//   return new CancelablePromise<T>(async (resolve, reject) => {
//     try {
//       const url = buildUrl(config, options);
//       const formData = getFormData(options);
//       const data = options.body !== undefined ? options.body : formData;

//       const axiosConfig: AxiosRequestConfig = {
//         url,
//         method: options.method as any,
//         headers: options.headers,
//         params: options.query,
//         data,
//         withCredentials: config.WITH_CREDENTIALS,
//       };

//       // 使用你的 requests，自动解包 data.data
//       const [err, resData] = await requests<T>(axiosConfig as any);
//       return [err, resData as T extends { data: any } ? T["data"] : T];
//       // if (err) return reject(err);
//       // resolve(resData as T);
//     } catch (e) {
//       reject(e);
//     }
//   });
// };
